<!--chatRoom不共用，当前只用于顶部设计师私聊-->
<!--目前只有私聊-->
<!--如果有群聊(添加传参,groupList,groupType[0.工程接入组 1.课件用户组 2.自定义群组])-->
<template>
    <chat
      ref="chatRoom" 
      :userList="userList"
      @filterUsers="getCompanyUsers">
      </chat>
</template>

<script>
  import {getCompanyUsers} from '@/api/boardcast_new.js'
  import encryption from '@/libs/encryption.js'
  import chat from "./components/chat"
  export default {
    name: 'chatRoom',
    props:[],
    components:{chat},
    data(){
      let October = sessionStorage.getItem('November')
      October = JSON.parse(encryption.SelfUseDecrypt(October))
      return {
      	USER_ID:October.userId,
//      USER_Name:October.nickname,
//      avatar:October.avatar,
				userList:[],
				userListbf:[],
      	queryCompanyUserInfo:{
	      	pageIndex:1,
	     	 	pageSize:2147483646,
	     	 	type:'designer',
	     	 	order:'desc',
	     	 	sortBy:'created',
	     	 	username:''
      	},
      	totalCount:0
      }
    },
    filters:{
    	
    },
    computed:{   
	
    },
    watch:{
    	
    },
    mounted(){
        this.getCompanyUsers(1);
    },
    beforeDestroy(){
    	
    },
    methods:{
	    //获取单位内试验员
        getCompanyUsers(page,userName){
        	if(this.userListbf.length > 0 && (this.userListbf.length == this.totalCount)){
        		if(userName){
	        		this.userList = this.userListbf.filter(user => user.userName.indexOf(userName)!=-1);
	        	}else{
	        		this.userList = this.userListbf
	        	}
        		return
        	}
        	if(page == 1){
        		this.userList = [];
        		this.userListbf = [];
        		this.queryCompanyUserInfo.pageIndex  = page;
        	}else{
        		this.queryCompanyUserInfo.pageIndex ++; 
        	}
        	if(userName){
        		this.queryCompanyUserInfo.username = userName;
        	}else{
        		this.queryCompanyUserInfo.username = '';
        	}
	     	getCompanyUsers(this.queryCompanyUserInfo).then(data => {
	     	 	if(data.code == 1){
	     	 		 this.totalCount = (data.data.total) - 1;
	     	 		 let users = data.data.items.filter(user => user.id != this.USER_ID);
	     	 		 this.userListbf = this.userListbf.concat(users);
	     	 		 this.userList = this.userList.concat(users);
	     	 		 this.userList.forEach((user) => {
	     	 		 	 this.$set(user,'userId',user.id);
	     	 		 	 this.$set(user,'userName',user.username);
	     	 		 	 this.$set(user,'msgList',[]); //当前显示消息
	     	 		 	 this.$set(user,'msgCount',0); //当前未读消息数
	     	 		 });
	     	 	}else{
	     	 		
	     	 	}
	     	})
	    },
	    updateUser(){
	    	this.getCompanyUsers(1);
	    }
    },
    destroyed() {
      
    }
  }
</script>

<style>
	
</style>
